package leetcode.dynamic;

import java.util.Arrays;

public class Lc322 {


    public static int coinChange(int[] coins, int amount) {

        int[] dp = new int[amount + 1];
        Arrays.fill(dp, Integer.MAX_VALUE);
        dp[0] = 0;
//        for (int i = 0; i < coins.length; i++) {
//            dp[coins[i]] = 1;
//        }
        for (int i = 1; i <= amount; i++) {
            for (int j = 0; j < coins.length; j++) {
                if (i - coins[j] >= 0 && dp[i - coins[j]] != Integer.MAX_VALUE) {
                    dp[i] = Math.min(dp[i - coins[j]] + 1, dp[i]);
                }
            }
        }
        return dp[amount] == Integer.MAX_VALUE ? -1 : dp[amount];
    }

    public static void main(String[] args) {
        int [] arr = {1,2,5};
        int a = 11;
        System.out.println(coinChange(arr, a));
    }

}
